package br.com.ngame.manager;

import java.applet.Applet;
import java.applet.AudioClip;
import java.util.HashMap;
import java.util.Vector;

public class AppletSoundManager implements SoundManager
{
	protected HashMap<String,Vector<AudioClip>> collections;
	protected Applet applet;
	private boolean soundsInResource = true;
	
	public AppletSoundManager(Applet applet)
	{
		this.applet = applet;
		collections = new HashMap<String,Vector<AudioClip>>();
	}
	
	public void loadSoundCollections(String[] fileNames)
	{
		for (int i=0; i<fileNames.length; i++)
		{
			loadSoundCollection(fileNames[i]);
		}
	}
	
	public void loadSoundCollection(String fileName)
	{
		loadSound(fileName);
	}
	
	public void loadSound(String fileName)
	{
		Vector<AudioClip> vect = new Vector<AudioClip>();
		AudioClip sound = applet.getAudioClip(applet.getDocumentBase(), fileName);
		vect.add( sound );
		collections.put(fileName, vect);
	}
	
	public AudioClip getSound(String fileName, int soundIndex)
	{
		return collections.get(fileName).get(soundIndex);
	}
	
	public AudioClip getSound(String fileName)
	{
		return collections.get(fileName).get(0);
	}
	
	public int getSoundCount(String fileName)
	{
		return collections.get(fileName).size();
	}

	public boolean isSoundsInResource() {
        return soundsInResource;
    }

    public void setSoundsInResource(boolean value) {
        soundsInResource = value;
    }
}
